package com.cefa.edu.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.cefa.edu.common.result.FailureResult;
import com.cefa.edu.common.result.ReturnMessage;
import com.cefa.edu.common.result.SuccessResult;
import com.cefa.edu.model.EduStage;
import com.cefa.edu.service.EduStageService;
import com.cefa.edu.common.result.Result;
import net.logstash.logback.encoder.org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by cc664 on 2018/8/3.
 */
@RestController
public class EduStageController {

    private Logger logger=LoggerFactory.getLogger(EduStageController.class);
    @Autowired
    private EduStageService eduStageService;

    /**
     * @aa 根据学生id 获取对应的学习阶段数据
     * @aa 封装返回的数据到Result对象中 并返回
     */
    @RequestMapping("/education/getEduStages/{userId}")
    public Result<List<HashMap<String,Object>>> getEduStagesByUserId(@PathVariable String userId){
      if(StringUtils.isNotBlank(userId)){

          //根据学生id 获取对应的学习阶段数据
          List<HashMap<String,Object>> stagelist=null;
          try{
            stagelist= eduStageService.getEduStageByUserId(Integer.parseInt(userId));
          }catch(Exception e){
              logger.error("获取指定学生id的学生学习阶段数据时，出错！");
              e.printStackTrace();
              return new FailureResult<List<HashMap<String, Object>>>(new ReturnMessage("500","failure"));
          }

          //封装返回的数据到Result对象中 并返回
           SuccessResult result=new SuccessResult(new ReturnMessage("200","success"));
           if(stagelist!=null && stagelist.size()>0){
               result.setData(stagelist);
               return result;
           }else{
               return result;
           }

      }

      return null;
    }

}
